import { NoSkinCellRenderer } from "../../../common/item/NoSkinCellRenderer";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../../common/ObjCreate";
import { LoaderHelp } from "../../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../../resource/ResFileConst";
import { SArenaCrossFightRecord } from "../../../../../../Message/Public/SArenaCrossFightRecord";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { ArenaLose } from "../../../../../../ImagesConst/ArenaLose";
import { ArenaWin } from "../../../../../../ImagesConst/ArenaWin";
//class ArenaCrossFightRecordCellRenderer
    
    export  class ArenaCrossFightRecordCellRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._bmpLeft = new Object /* flash.display.Bitmap */();
            this._bmpLeft.x = 10;
            this._bmpLeft.y = 5;
            this.addChild(this._bmpLeft);
            var loc1=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6);
            this._tfLeft = ObjCreate.createTextField("", 80, 25, 180, 20, this, loc1);
            this._tfRight = ObjCreate.createTextField("", 360, 25, 180, 20, this, loc1);
            this._btnLook = ObjCreate.createGButton("观看", 281, 40, 50, 22, this);
            this._btnLook.addEventListener(flash.events.MouseEvent.CLICK, this.onClickLook);
            this._tfNoRecord = ObjCreate.createTextField("无记录", 283, 43, 50, 20, this, GlobalStyle.textFormat6);
            this._tfNoRecord.visible = false;
            this._bmpRight = new Object /* flash.display.Bitmap */();
            this._bmpRight.x = 540;
            this._bmpRight.y = 5;
            this.addChild(this._bmpRight);
            LoaderHelp.addResCallBack(ResFileConst.arena, this.onResCompl);
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._isResCompl = true;
            this.updateBitmap();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "sarenacrossfightrecord") 
            {
                this._fightRecord = arg1 as SArenaCrossFightRecord;
                this._isLeftWin = EntityUtil.toString(this._fightRecord.entityIdWin) > EntityUtil.toString(this._fightRecord.entityIdLose);
                this.updateView();
            }
            return;
        }

        /* internal  */onClickLook(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._fightRecord) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossLookVideo, this._fightRecord.fightRecordId));
            }
            return;
        }

        /* internal  */updateView(): void
        {
            var loc1="[" + EntityUtil.getProxyName(this._fightRecord.entityIdWin) + "]" + this._fightRecord.nameWin;
            var loc2="[" + EntityUtil.getProxyName(this._fightRecord.entityIdLose) + "]" + this._fightRecord.nameLose;
            this._tfLeft.text = this._isLeftWin ? loc1 : loc2;
            this._tfRight.text = this._isLeftWin ? loc2 : loc1;
            var loc3=Boolean(this._fightRecord.fightRecordId);
            this._tfNoRecord.visible = !loc3;
            this._btnLook.visible = loc3;
            this.updateBitmap();
            return;
        }

        /* internal  */updateBitmap(): void
        {
            if (this._isResCompl) 
            {
                this._bmpLeft.bitmapData = GlobalClass.getBitmapData(this._isLeftWin ? ImagesConst.ArenaWin : ArenaLose);
                this._bmpRight.bitmapData = GlobalClass.getBitmapData(this._isLeftWin ? ImagesConst.ArenaLose : ArenaWin);
            }
            return;
        }

        /* internal */ /* var */_fightRecord: SArenaCrossFightRecord;

        /* internal */ /* var */_isResCompl: Boolean=false;

        /* internal */ /* var */_isLeftWin: Boolean;

        /* internal */ /* var */_bmpLeft: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfLeft: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRight: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpRight: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnLook: GButton;

        /* internal */ /* var */_tfNoRecord: Object /* flash.text.TextField */;
    }
